//
//  XAspect-LaunchConfig.m 抽离原本应在AppDelegate的内容
//  YTT-IOS-CommonFramework
//
//  Created by aron on 2017/2/22.
//  Copyright © 2017年 aron. All rights reserved.
//

#import "AppDelegate.h"
#import "XAspect.h"
#import "BusinessInterface.h"
#import "UIColor+Util.h"
#import "UIView+Util.h"
#import "DBDatabaseConn+Initial.h"

#define AtAspect LaunchConfig

#define AtAspectOfClass AppDelegate
@classPatchField(AppDelegate)
AspectPatch(-, BOOL, application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions)
{
    NSLog(@"====LaunchConfig====");
    
    // 网络配置
    [self configNetInterface];
    
    // 数据库配置
    [self configDatabase];
    
    // UI
    [self initAppApparence];
    
    return XAMessageForward(application:application didFinishLaunchingWithOptions:launchOptions);
}


#pragma mark - ......::::::: init :::::::......


/**
 网络初始化
 */
- (void)configNetInterface {
    [FLInterfaceParam setPid:FLPID_DuoBao];
    id paramAndSerializer = [[BusinessInterfaceParamAndSerializer alloc] init];
    INTERFACER.businessParam = paramAndSerializer;
    INTERFACER.businessResponseSerializer = paramAndSerializer;
}

/**
 数据库初始化
 */
- (void)configDatabase {
    [[DBDatabaseConn sharedDBDatabaseConn] initDBWithAppGroupURL:nil];
}

/**
 *  全局的控件外观
 */
-(void)initAppApparence{
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    [[UINavigationBar appearance] setBarTintColor:[UIColor navBackgroundColor]];//NavBar背景色
    NSDictionary *navbarTitleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
    [[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];//NavBar字体颜色为白色
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];//NavBar图标颜色
    
    // BarButton属性设置
    NSDictionary* barbuttonAttr = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:14]};
    [[UIBarButtonItem appearance] setTitleTextAttributes:barbuttonAttr forState:UIControlStateNormal];
    
    [[UITabBar appearance] setTintColor:[UIColor tabTitleColor]];//底部TabBar选中颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor tabTitleColor]} forState:UIControlStateSelected];//底部TabBar字体选中颜色
    
    [UISearchBar appearance].tintColor = [UIColor whiteColor];
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setCornerRadius:10.0];
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setAlpha:0.8];
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont systemFontOfSize:12]];
    
    UIPageControl *pageControl = [UIPageControl appearance];
    pageControl.pageIndicatorTintColor = [UIColor colorWithHex:0xffffff alpha:0.5f];
    pageControl.currentPageIndicatorTintColor = [UIColor themeHighLightColor];
    
    [[UITextField appearance] setTintColor:[UIColor nameColor]];
    [[UITextView appearance]  setTintColor:[UIColor nameColor]];
}

@end
#undef AtAspectOfClass
#undef AtAspect
